<template>
  <view class="container">
    <van-cell-group>
      <van-cell title="昵称" :value="user.nickName" />
      <van-cell title="手机号码" :value="user.phonenumber" />
      <van-cell title="邮箱" :value="user.email" />
      <van-cell title="岗位" :value="postGroup"  />
      <van-cell title="角色" :value="roleGroup"  />
      <van-cell title="创建日期" :value="user.createTime" />
    </van-cell-group>
  </view>
   <view class="logout-container">
          <span class="logout-text" @click="logout">退出登录</span>
        </view>
</template>
<script setup>import { ref, onMounted } from 'vue'
import { getUserProfile } from '@/api/system/user'

const user = ref({})
const roleGroup = ref('')
const postGroup = ref('')
const logout = () => {
  
  uni.navigateTo({
     url: `/pages/login`,
  });
}
const getUser = () => {
  getUserProfile().then(response => {
    user.value = response.data
    roleGroup.value = response.roleGroup
    postGroup.value = response.postGroup
  })
}

onMounted(() => {
  getUser()
})

const handleLogout = () => {
  this.$modal.confirm('确定注销并退出系统吗？').then(() => {
    this.$store.dispatch('LogOut').then(() => {
      this.$tab.reLaunch('/pages/index')
    }).catch((error) => {
      console.error('注销失败:', error)
      this.$modal.msgError('注销失败，请稍后再试')
    })
  }).catch(() => {
    console.log('用户取消了注销操作')
  })
}
</script>

<style lang="scss">
  page {
    background-color: #ffffff;
  }
  .logout-text {
    color: gray;
    cursor: pointer;
    font-size: 16px;
  }
  
  .logout-container {
    margin-top: 20px;
    width: 100%;
    display: flex;
    justify-content: center;
  }
</style>
